package com.zhaoye.service.impl;

import com.zhaoye.service.IMessageProvider;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author feng
 * @Date 2021/11/17 21:34
 *  消息驱动关于消息绑定的发送方   绑定器、数据源(Source)、信道(channel)
 */
@EnableBinding(Source.class)
public class MessageProvicerImpl implements IMessageProvider {

    @Resource
    private MessageChannel output;       //消息发送的信道

    @Override
    public String send() {
        String serial = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(serial).build());
        System.out.println("*** serial:"+ serial);
        return null;
    }
}
